<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/pages/common/header.jsp"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>航线抓取统计</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/datePicker/WdatePicker.js"></script>

<style type="text/css">

.huadong{
	width:100%;
	height:55px;
	overflow:hidden;
	/*background-image:url('huadong/img/bg.png');  */     
    background-repeat:no-repeat;                   
    background-position:center center ;
    position:relative;
}
.huadong ul{
	display:block;
	padding:0px;
	position:absolute;
	padding: 0px;
	list-style:none;
	margin:0px;
	left:45px;
	top:5px;
	width:77%;
	height:45px;
}
.huadong ul li{
	list-style: none;
	float: left;
	display:block;
	text-align: center;
	width:12%;
	padding:1px;
	border-color: #C0C0C0;
	border-style:solid;
}


.huadong ul li:hover{ background-color:#FFFF00;}



.huadong ul li a{
	display:block;	
	width:100%;
	height:100%;
	text-decoration: none;
	text-align:center;
	/*line-height: 40px;*/
	overflow: hidden; 
	text-overflow:ellipsis;
	margin:0 auto 0 auto;;
	border:0px;
	outline:none; 
	blr:expression(this.onFocus=this.blur());	
}

.huadong #_huadong_pre_a{
	float:left;
	background:url('<%=request.getContextPath() %>/images/base/icon_arrow.png') 0 0 no-repeat;
	display:block;
	position:relative;
	width:43px;
	height:45px;
	margin:0px;
	padding:0px;
	margin-top: 5px;
	outline:none; 
	cursor:pointer;
	
}

.li_yellow{
list-style: none;
	float: left;
	display:block;
	text-align: center;
	width:12%;
	padding:1px;
	border-color: #C0C0C0;
	border-style:solid;
	background-color:#FFFF00;
}

.huadong #_huadong_pre_a:HOVER{
	background-position:0 -100px;
}
.huadong #_huadong_next_a{
	float:left;
	background:url('<%=request.getContextPath() %>/images/base/icon_arrow.png') -100px 0 no-repeat;
	display:block;
	position:relative;
	width:43px;
	height:45px;
	margin:0px;
	padding:0px;
	margin-top:5px;
	outline:none; 
	cursor:pointer;
	left:70%;
}
.huadong #_huadong_next_a:HOVER{
	background-position:-100px -100px;
}

.huadong input{
	float:left;
	display:block;
	position:relative;
	top:10px;
	height:25px;
	margin:0px;
	padding:0px;
	margin-top: 5px;
	outline:none; 
	cursor:pointer;
	left:74%;
}
</style>

<script type="text/javascript">

var type="single";
var reprotDate=getYetoDay();

$(function (){
	$("#btn_single").attr("disabled","disabled");
	$("#btn_double").removeAttr("disabled"); 
	click(getYetoDay());
	
	$("#btn_single").bind('click',function(){
		type="single";
		click(reprotDate);
		$("#btn_single").attr("disabled","disabled");
		$("#btn_double").removeAttr("disabled"); 
	});
	
	$("#btn_double").bind('click',function(){
		type="double";
		click(reprotDate);
		$("#btn_double").attr("disabled","disabled");
		$("#btn_single").removeAttr("disabled"); 
	});
	
	
	
});

function getDateStr(myDate){
	var year =myDate.getFullYear();
	var month =myDate.getMonth()+1;
	if(month<10){
		month="0"+month;
	}
	var day=myDate.getDate();
	if(day<10){
		day="0"+day;
	}
	return year+"-"+month+"-"+day;
}

function getYetoDay(){
	var myDate=new Date();
	var times=myDate.valueOf();
	times=times-24 * 60 * 60 * 1000;
	return getDateStr(new Date(times));
}

function click(date){
	var today=getDateStr(new Date());
	if(date>=today){
		alert("只能查今天之前的统计");
		return;
	}
	if(date<"2013-03-01"){
		alert("只能查2013-03-01之后的统计");
		return;
	}
	var url="<%=contextPath %>/preprocess-AirLineCount-dayLines.action";
	var datas ={"date":date,"type":type};
	$.ajax({
		url: url,
		type: 'POST',
		data:  datas,
		dataType: 'json',
		error: function(){
			alert('查询统计出错,请重新查询');
		},
		success: function(data){
			if(null!=data.result && "undefined"!=data.result && ""!=data.result){
				alert(data.result);
				return;
			}
			reprotDate=date;
			$('#span_date').html(date);
			$('#span_web').html(data.channelSize);
			$('#span_airLine').html(data.lineSize);
			$('#ul_id').html('');
			var count=1;
			$.each(data.listDay, function(idx, e){
				count++;
				if(date==e.grabDate){
					$('#ul_id').append('<li class="li_yellow"><a href="javascript:click(\''+e.grabDate+'\');"><span>'+e.grabDate+
							'</span><br><span style="color:Red">'+e.flightSize+'</span></a></li>');
					$('#span_flight').html(e.flightSize);
				}else{
					$('#ul_id').append('<li ><a href="javascript:click(\''+e.grabDate+'\');"><span>'+e.grabDate+
							'</span><br><span style="color:Red">'+e.flightSize+'</span></a></li>');
				}
					
			});
			for(;count<8;count++){
				$('#ul_id').append('<li ><span>---</span><br><span>---</span></li>');
			}
			
			$('#table_channel').html('');
			$('#table_channel').append('<tr><td style="height:35px;">渠道</td> '
				+'<td>渠道名称</td><td>日期</td><td>航线数</td><td>航班数</td></tr>');
			$.each(data.dayChannel, function(idx, e){
				$('#table_channel').append('<tr>'
						+'<td style="height:35px;"><a href="javascript:clickChannel(\''+e.channel+'\');">'+e.channel+'</a></td>'
						+'<td>'+e.channelName+'</td>'
						+'<td>'+e.grabDate+'</td>'
						+'<td><a href="javascript:clickDate(\''+e.grabDate+'\',\''+e.channel+'\');">'+e.tripsSize+'</a></td>'
						+'<td>'+e.flightSize+'</td>'
						+'</tr>');
				
			});
		}

	});
}

function clickChannel(channel){
	top.f_addTab(null, '渠道航线统计查询',
			"preprocess-AirLineCount-channelList.action?channel=" + channel+"&type="+type+"&method="+"channel");
}

function clickDate(date,channel){
	top.f_addTab(null, '航线统计查询',
			"preprocess-AirLineCount-AirLineList.action?channel=" + channel+"&type="+type+"&date="+date+"&method="+"airLine");
}

function btnClickFun(){
	var date=$("#in_day_ID").val();
	if(""==date ){
		alert("请输入日期");
	}else{
		click(date);
	}
}

function next(){
	var date=reprotDate.replace(/-/g,"/");
	var myDate = new Date(date);
	var times=myDate.valueOf();
	times=times+24 * 60 * 60 * 1000;
	var dateStr=getDateStr(new Date(times));
	click(dateStr);
}

function pre(){
	var date=reprotDate.replace(/-/g,"/");
	var myDate = new Date(date);
	var times=myDate.valueOf();
	times=times-24 * 60 * 60 * 1000;
	var dateStr=getDateStr(new Date(times));
	click(dateStr);
}

</script>

</head>
<body>

<div class="searchtitle" style="width :1100px;">
	<br>
	<br>
	<div >
		<div >
			<table  style="width:98%;height:100%;padding-left:40px;" class="form2column">
				<tr >
					<td style="width:20%;height:35px;">日期：</td><td style="width:20%;"><span id="span_date"></span></td>
					<td style="width:20%;">目标网站个数：</td><td style="width:20%;"><span id="span_web"></span></td>
					<td><input type="button" id="btn_single" value="单程"/></td>
				</tr>
				<tr>
					<td style="width:20%;">航线数：</td><td style="width:20%;"><span id="span_airLine"></span></td>
					<td style="width:20%;">航班数：</td><td style="width:20%;"><span id="span_flight"></span></td>
					<td><input type="button" id="btn_double" value="往返"/></td>
				</tr>
				
			</table>
		</div>
		<div class="huadong">
			<a id="_huadong_pre_a" href="javascript:pre()" ></a>
			<ul id="ul_id">
		
			</ul>
			<a id="_huadong_next_a" href="javascript:next()"></a>
			<input name="inputDate" type="text"	id="in_day_ID" style="width: 120px"    
						onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'2013-03-01',maxDate:'%y-%M-{%d-1}'})" readonly="readonly"/>
			<input type="button" id="btn_01" value="确定" onclick="btnClickFun();"/>
			
		</div>
		<div>
			<table id="table_channel" style="width:98%;height:100%;padding-left:40px;" class="form2column">
			</table>
		</div>
	</div>
</div>
<br>
<br>
</body>
</html>